package top.liujingyanghui.crypto.mybatisplus.rule;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import top.liujingyanghui.crypto.mybatis.rule.AbstractCryptoRule;

/**
 * 身份证号加解密
 *
 * @author : wdh
 * @since : 2022/5/23 16:15
 */
public class IdNumCryptoRule extends AbstractCryptoRule {

    private final String KEY = "45645733dg35h6h7";
    private final AES AES = SecureUtil.aes(KEY.getBytes());

    /**
     * 数据加密
     */
    public String encrypt(String content) {
        try {
            return AES.encryptHex(content);
        } catch (Exception e) {
            return content;
        }
    }

    /**
     * 数据解密
     */
    public String decrypt(String content) {
        try {
            return AES.decryptStr(content);
        } catch (Exception e) {
            return content;
        }
    }
}
